/*
 * @file    print_matrix.cpp
 * @author  edward <libo@tencent.com>
 * @date    2013-04-05
 * @brief   
 * */

#include <iostream>
#include <assert.h>

using namespace std;
#define MAX_COL 8

void print_matrix(int ar[][MAX_COL], int r, int c, int k) {
    if(r < 1 || c < 1) {
        return;
    }

    if(r == 1) {
       for(int i=0; i < c; i++) {
           cout << ar[k][k + i] << " ";
       }
    }

    if(c == 1) {
       for(int i=0; i < r; i++) {
           cout << ar[k + i][k] << " ";
       }
    }

    if( r > 1 && c > 1) {
        //top
        for(int i = 0; i < c - 1; ++i) {
            cout << ar[k][k+i] << " ";
        }
        //right
        for(int i = 0; i < r - 1; ++i) {
            cout << ar[k + i][k + c - 1] << " ";
        }
        //bottom
        for(int i = 0; i < c -1 ; ++i) {
            cout << ar[k + r -1][k + c -1 -i] << " ";
        }
        //left
        for(int i = 0; i < r - 1; ++i) {
            cout << ar[k + r -1 -i][k] << " ";
        }
        print_matrix(ar, r -2 , c -2, k + 1);
    }
}

int main() {
    int matrix[][MAX_COL] = { {11, 13, 43, 10},
                              {34, 65, 23, 1},
                              {54, 23, 12, 4} };
                              //{65, 23, 54, 1} };
    print_matrix(matrix, 3, 4, 0);
}

